package org.example.sportdemo.service;

import org.example.sportdemo.entity.Ground;
import org.example.sportdemo.mapper.GroundMapper;
import org.example.sportdemo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class GroundService {

    @Autowired
    private GroundMapper groundMapper;

    public List<Ground> selectAll(){
        return groundMapper.selectAll();
    }

    public PageUtils queryPage(Map<String, Object> params) {
        //总数据
        List<Ground> groundList = groundMapper.selectAll();
        //总条数
        Integer totalCount = groundMapper.selectCount();
        //当前页
        Integer currPage = Integer.valueOf((String) params.get("currPage"));
        //每页条数
        Integer pageSize = Integer.valueOf((String) params.get("pageSize"));
        return new PageUtils(totalCount,(Integer) pageSize,currPage,groundList);
    }

    public void addGround(Ground ground) {

        Date date = new Date();
        ground.setCreate_time(date);
        groundMapper.addGround(ground);

    }

    public Ground selectById(Integer id) {
        return groundMapper.selectById(id);
    }

    public void updateGround(Ground ground) {
        groundMapper.updateGround(ground);
    }

    public void deleteByIds(Integer[] ids) {
        groundMapper.deleteByIds(ids);
    }

    public List<Ground> selectForHot() {
        return groundMapper.selectForHot();
    }
}
